import configparser
import pymysql
from faker import Faker


faker = Faker(locale='zh_CN')

# 创建配置解析器对象
config = configparser.ConfigParser()

# 读取配置文件
config.read('./config.ini')

# 访问配置项
print("ServerAliveInterval:", config.get(section='Database1', option='host'))
# print("Compression:", config.get('Database2', 'password'))


def get_data_from_database():
    connection = pymysql.connect(host=config['Database1']['host'],
                                 user=config['Database1']['user'],
                                 password=config['Database1']['password'],
                                 database='hotmaxx_crm')  # Replace with your database name
                                 # database='test_db')

    # try:
    #     with connection.cursor() as cursor:
    #         sql = "SELECT id,phone FROM eb_hotmaxx_user WHERE nickname =%s"
    #         cursor.execute(sql, ('刘陆',))
    #         query_result = cursor.fetchone()
    #         return query_result
    # finally:
    #     connection.close()

name_list = [faker.name() for _ in range(100)]
phone_list = [faker.phone_number() for _ in range(100)]
email_list = [faker.email() for _ in range(100)]
age_list = [faker.random_int(min=18, max=60) for _ in range(100)]
sex_list = [faker.random_element(elements=('男', '女')) for _ in range(100)]
def insert_data_to_database():
    connection = pymysql.connect(host=config['Database1']['host'],
                                 user=config['Database1']['user'],
                                 password=config['Database1']['password'],
                                 database='hotmaxx_crm')

    try:
        with connection.cursor() as cursor:
            for name, phone, email in zip(name_list, phone_list, email_list):
                sql = "INSERT INTO api_auto_test_liulu (name, phone,email) VALUES (%s, %s,%s)"
                cursor.execute(sql, (name, phone, email))
                connection.commit()
    finally:
        connection.close()


print(insert_data_to_database())